<?php 
$this->headTitle($this->translator('bizprofile_user_registerenterprise_title'));
$this->headLink()
    ->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.all.css');
$this->headScript()
    ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate/jquery.validate.min.js');
?>

<?php if($this->enterprise != null): ?>
<script type="text/javascript" src="<?php echo $this->APP_STATIC_SERVER; ?>/js/tinymce/tiny_mce.js"></script>
<div class="t_bizprofile_register">
	<h2><?php echo $this->translator('bizprofile_user_addenterpriseinfo_title') ?></h2>
	<div class="message"><?php echo $this->flashMessenger(); ?></div>
	<form method="post" action="<?php echo $this->url(array(), 'bizprofile_user_add_enterprise_info'); ?>" id="addEnterpriseInfoForm">
		 <div class="clearfix">		
            <label><?php echo $this->translator('info_language'); ?>:</label>
            <?php 
				echo $this->languageSelector(array(
										'id'   => 'languageSelector', 
										'name' => 'languageSelector',										
									), $this->translatableData);
				?>
        </div>
		 <div class="clearfix">
            <label><?php echo $this->translator('info_source_item'); ?>:</label>
             <div class="translatable translationSourceItems">
            <?php 
            	echo $this->translatableEnterpriseInfo(array(
									'id'       => 'sourceItem',
									'name'     => 'sourceItem',
									'selected' => (null == $this->sourceInfo) ? null : $this->sourceInfo->info_id,
									'disabled' => (null == $this->sourceInfo) ? null : $this->sourceInfo->info_id,
								), $this->lang);
				
				?>
				</div>
        </div>
        
		 <div class="clearfix">
            <label><?php echo $this->translator('info_title'); ?>:</label>
            <input type="text" id="title" name="title" style="width: 300px" />
        </div>
        
		 <div class="clearfix">
            <label><?php echo $this->translator('info_string'); ?>:</label>            
            <textarea name="content" id="content" class="tinymce" style="width: 440px; height: 100px"></textarea>
        </div>
        
		 <div class="clearfix">
            <label><?php echo $this->translator('info_number'); ?>:</label>
            <select name="number" id="number">
            	<?php for($i = 1; $i <= 5; $i++ ) :?>
            		<option value="<?php echo $i?>"><?php echo $i; ?></option>
            	<?php endfor; ?>
            </select>
        </div>
               
        <div class="clearfix">
			<label>&nbsp;</label>
			<?php echo $this->tokenElement; ?>
			<button type="submit"><span><?php echo $this->translator('bizprofile_user_add_button'); ?></span></button>
			<button type="reset"><span><?php echo $this->translator('bizprofile_user_register_reset_button'); ?></span></button>
		</div>
     </form>
</div>
<div id="messageDialog"></div>

<script type="text/javascript">
/**
 * Upload handlers
 */
function onUploadComplete(event, ID, fileObj, response, data) {
	var images = $.evalJSON(response);

	var presentImage = $('<img/>');
	$(presentImage).attr('src', images.thumbnail.url)
		.attr('width', '100').attr('height', '100')
		.attr('style', 'cursor: pointer')
		.click(function() {
			selectImage(images);
		});
	var select = $('<select/>');
	$(select).attr('width', '100');
	$('<option/>').attr('value', '').html('---').appendTo(select);

	for (var thumb in images) {
		$('<option/>').attr('value', images[thumb].url).html(images[thumb].size).appendTo(select);
	}
	$(select).change(function() {
		if ($(this).val() != '') {
			insertImage($(this).val());
		}
	});

	$('<li/>').append(presentImage).append($('<br/>')).append(select).appendTo($('#photos'));
};

function selectImage(images) {
	var urls = {};
	for (var thumb in images) {
		urls[thumb] = images[thumb].url; 
	}
	$('#articleImage').val($.toJSON(urls));
	$('#articleImageContainer').html('<img src="' + images.crop.url + '" />');	
};

/**
 * Insert image to TinyMCE editor at current position
 * @param string url The image url
 */
function insertImage(url) {
	tinyMCE.getInstanceById('content').execCommand('mceInsertContent', false, '<img src="' + url + '" />');
};

/**
 * Init TinyMCE instances
 */
tinyMCE.init({
	theme: 'advanced',
	theme_advanced_toolbar_location: 'top',
	theme_advanced_toolbar_align: 'left',
	width: '440',
	height: '225',
	mode: 'exact',
	elements: 'description',
	content_css: '<?php echo $this->APP_STATIC_SERVER; ?>/skins/<?php echo $this->APP_TEMPLATE; ?>/<?php echo $this->APP_SKIN; ?>/default.css',
	relative_urls: false,
	remove_script_host: false
});

tinyMCE.init({
	theme: 'advanced',
	plugins: 'safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager,preelementfix',
	theme_advanced_buttons2: 'cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo',
	theme_advanced_buttons3: 'link,unlink,anchor,image,cleanup,code,|,preview,|,forecolor,backcolor',
	theme_advanced_buttons4: 'tablecontrols,ltr,rtl',  //"tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,fullscreen",
	theme_advanced_toolbar_location: 'top',
	theme_advanced_toolbar_align: 'left',
	width: '440',
	mode: 'exact',
	elements: 'content',
	content_css: '<?php echo $this->APP_STATIC_SERVER; ?>/skins/<?php echo $this->APP_TEMPLATE; ?>/<?php echo $this->APP_SKIN; ?>/default.css',
	relative_urls: false,
	remove_script_host: false,
	onchange_callback: function(editor) {
		tinyMCE.triggerSave();
		$('#' + editor.id).valid();
	}
});

/**
 * Insert clip to TinyMCE editor at current position
 */
function insertFile() {
	var htmlCode = $('#fileHtmlCode').attr('value');
	if (null != htmlCode && '' != htmlCode) {
		tinyMCE.getInstanceById('content').execCommand('mceInsertContent', false, '<div class="clearfix" style="text-align: center">' + htmlCode + '</div>');
	} else {
		var file   = ($('#fileUrl').attr('value') != null) ? $('#fileUrl').attr('value') : null;
		var image  = ($('#fileImage').attr('value') != null) ? $('#fileImage').attr('value') : null;
		var width  = ($('#fileWidth').attr('value') != null) ? $('#fileWidth').attr('value') : '450';
		var height = ($('#fileHeight').attr('value') != null) ? $('#fileHeight').attr('value') : '337';
		tinyMCE.getInstanceById('content').execCommand('mceInsertContent', false, '<div class="clearfix" style="text-align: center"><object width="' + width + '" height="' + height + '" type="application/x-shockwave-flash" data="<?php echo $this->APP_STATIC_SERVER; ?>/js/jwplayer/player.swf" style="visibility: visible"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="menu" value="false" /><param name="flashvars" value="play=true&repeat=true&autostart=false&file=' + file + '&image=' + image + '" /></object></div>');
	}
};

function onUploadCompleteFile(event, ID, fileObj, response, data) {
	var res = $.evalJSON(response);
	$('#fileUrl').attr('value', res.original.url);
};

function onUploadCompleteFileImage(event, ID, fileObj, response, data) {
	var res = $.evalJSON(response);
	$('#fileImage').attr('value', res.original.url);
};

$(document).ready(function() {
	/**
	 * Validate form
	 */
	$('#addEnterpriseInfoForm').validate({
		rules: {
			title: {
		  		required: true
			}
	    },
	    messages: {
	    	title: {
	        	required: "<?php echo $this->translator('info_title_required'); ?>"
			}
		}
	});
});
</script>
<?php endif; ?>